﻿using System;
using System.Collections.Generic;
using System.Linq;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Admin.Models.ConfigManager;
using Zocono.WCS.Infrastructure.ApllicationDto.Enums;

namespace Zocono.WCS.Admin.Models.WorkTaskManager
{
    public class WorkTaskInfoPageData
    {
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        public long RouteID { get; set; }
        public string Js_RouteID { get { return RouteID.ToString(); } }
        public string FromStation { get; set; }
        public string ToStation { get; set; }
        public int Priority { get; set; }
        public string PalletCode { get; set; }
        public int TaskCode { get; set; }
        /// <summary>
        /// 取值枚举EnumTaskProcessState
        /// </summary>
        public int TaskProcessState { get; set; }
        /// <summary>
        /// 取值枚举EnumTaskState
        /// </summary>
        public int TaskState { get; set; }
        /// <summary>
        /// 取值枚举EnumTaskType
        /// </summary>
        public int TaskType { get; set; }
        public DateTime SaveTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public long WmsTaskCode { get; set; }
        public long DependWmsTaskCode { get; set; }
        public string WmsFromStation { get; set; }
        public string WmsFromPosition { get; set; }
        public string WmsToStation { get; set; }
        public string WmsToPosition { get; set; }
        public long CurrentRounteDetailID { get; set; }
        /// <summary>
        /// 取值枚举EnumDetailTaskState
        /// </summary>
        public int CurrentDetailTaskState { get; set; }
        /// <summary>
        /// 取值枚举EnumDispatchType
        /// </summary>
        public int CurrentDispatchType { get; set; }
        public string CurrentFromEquipment { get; set; }
        public string CurrentFromCargo { get; set; }
        public string CurrentToEquipment { get; set; }
        public string CurrentToCargo { get; set; }
        public DateTime CurrentCreateTime { get; set; }
        public DateTime CurrentUpdateTime { get; set; }
        /// <summary>
        /// 上传WMS状态：0-未上传；1-成功；2-失败
        /// 取值枚举EnumUploadWmsState
        /// </summary>
        public int UploadWmsState { get; set; } = 0;
        /// <summary>
        /// 上传WMS时间
        /// </summary>
        public DateTime UploadWmsTime { get; set; } = new DateTime(1900, 1, 1);



        private const string DATE_STRING_FORMAT = "yyyy-MM-dd HH:mm:ss";
        private readonly DateTime defaultTime = new DateTime(1900, 1, 1);
        public string RouteInfo { get { return $"{FormatEqument(CurrentFromEquipment)}->{FormatEqument(CurrentToEquipment)}"; } }
        /// <summary>
        /// 格式化设备号
        /// </summary>
        /// <param name="eq"></param>
        /// <returns></returns>
        public string FormatEqument(string eq)
        {
            if (eq.Contains("SC4"))
            {
                return eq.Replace("SC4", "四楼堆垛机");
            }
            else if (eq.Contains("SC3"))
            {
                return eq.Replace("SC3", "三楼堆垛机");
            }
            else if (eq.Contains("SC2"))
            {
                return eq.Replace("SC2", "二楼堆垛机");
            }

            return eq;
        }
        public string TaskProcessStateFormat
        {
            get
            {
                var result = TaskProcessState.ToString();
                var item = TaskProcessStateItem.TaskProcessStateDatasource.FirstOrDefault(c => c.TaskProcessStateValue == TaskProcessState);
                if (item != null)
                {
                    result = item.TaskProcessStateName;
                }

                return result;
            }
        }

        public string TaskStateFormat
        {
            get
            {
                var result = TaskState.ToString();
                var item = TaskStateItem.TaskStateDatasource.FirstOrDefault(c => c.TaskStateValue == TaskState);
                if (item != null)
                {
                    result = item.TaskStateName;
                }

                return result;
            }
        }

        public string TaskTypeFormat
        {
            get
            {
                var result = TaskType.ToString();
                var item = TaskTypeItem.TaskTypeDatasource.FirstOrDefault(c => c.TaskTypeValue == TaskType);
                if (item != null)
                {
                    result = item.TaskTypeName;
                }

                return result;
            }
        }

        public string CurrentDetailTaskStateFormat
        {
            get
            {
                var result = CurrentDetailTaskState.ToString();
                var item = DetailTaskStateItem.DetailTaskStateDatasource.FirstOrDefault(c => c.DetailTaskStateValue == CurrentDetailTaskState);
                if (item != null)
                {
                    result = item.DetailTaskStateName;
                }

                return result;
            }
        }

        /// <summary>
        /// 调度类型说明
        /// </summary>
        public string DispatchTypeDescription { 
            get { 
                var result = ((EnumDispatchType)Enum.Parse(typeof(EnumDispatchType), CurrentDispatchType.ToString())).GetDescription();
                return result;
            } 
        }

        public string CurrentDispatchTypeFormat
        {
            get
            {
                var result = CurrentDispatchType.ToString();
                var item = DispatchTypeItem.DispatchTypeDatasource.FirstOrDefault(c => c.DispatchTypeValue == CurrentDispatchType);
                if (item != null)
                {
                    result = item.DispatchTypeName;
                }

                return result;
            }
        }

        public string SaveTimeFormat
        {
            get
            {
                if (SaveTime <= defaultTime)
                {
                    return "";
                }

                return SaveTime.ToString(DATE_STRING_FORMAT);
            }
        }
        public string UpdateTimeFormat
        {
            get
            {
                if (UpdateTime <= defaultTime)
                {
                    return "";
                }

                return UpdateTime.ToString(DATE_STRING_FORMAT);
            }
        }
        public string CurrentCreateTimeFormat
        {
            get
            {
                if (CurrentCreateTime <= defaultTime)
                {
                    return "";
                }

                return CurrentCreateTime.ToString(DATE_STRING_FORMAT);
            }
        }
        public string CurrentUpdateTimeFormat
        {
            get
            {
                if (CurrentUpdateTime <= defaultTime)
                {
                    return "";
                }

                return CurrentUpdateTime.ToString(DATE_STRING_FORMAT);
            }
        }
        public string UploadWmsTimeFormat
        {
            get
            {
                if (UploadWmsTime <= defaultTime)
                {
                    return "";
                }

                return UploadWmsTime.ToString(DATE_STRING_FORMAT);
            }
        }

        public string UploadWmsStateFormant
        {
            get
            {
                var result = UploadWmsState.ToString();
                var item = UploadWmsStateItem.Datasourcce.FirstOrDefault(c => c.UploadWmsStateValue == UploadWmsState);
                if (item != null)
                {
                    result = item.UploadWmsStateName;
                }

                return result;
            }
        }

    }


    public class TaskRouteDetailInfoPageData
    {
        private const string DATE_STRING_FORMAT = "yyyy-MM-dd HH:mm:ss";
        private readonly DateTime defaultTime = new DateTime(1900, 1, 1);
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        public long TaskID { get; set; }
        public string Js_TaskID { get { return TaskID.ToString(); } }
        public long RouteDetailID { get; set; }
        public string Js_RouteDetailID { get { return RouteDetailID.ToString(); } }
        /// <summary>
        /// 取值枚举EnumDetailTaskState
        /// </summary>
        public EnumDetailTaskState DetailTaskState { get; set; }
        /// <summary>
        /// 取值枚举EnumDispatchType
        /// </summary>
        public EnumDispatchType DispatchType { get; set; }
        public string FromEquipment { get; set; }
        public string FromCargo { get; set; }
        public string ToEquipment { get; set; }
        public string ToCargo { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }

        public string CreateTimeFormat
        {
            get
            {
                if (CreateTime <= defaultTime)
                {
                    return "";
                }

                return CreateTime.ToString(DATE_STRING_FORMAT);
            }
        }

        public string UpdateTimeFormat
        {
            get
            {
                if (UpdateTime <= defaultTime)
                {
                    return "";
                }

                return UpdateTime.ToString(DATE_STRING_FORMAT);
            }
        }


        public string DetailTaskStateFormat
        {
            get
            {
                var result = ((EnumDetailTaskState)Enum.Parse(typeof(EnumDetailTaskState), DetailTaskState.ToString())).GetDescription();
                return result;
                //var result = DetailTaskState.ToString();
                //var item = DetailTaskStateItem.DetailTaskStateDatasource.FirstOrDefault(c => c.DetailTaskStateValue == DetailTaskState);
                //if (item != null)
                //{
                //    result = item.DetailTaskStateName;
                //}

                //return result;
            }
        }
       

        /// <summary>
        /// 调度类型说明
        /// </summary>
        public string DispatchTypeDescription
        {
            get
            {
                var result = ((EnumDispatchType)Enum.Parse(typeof(EnumDispatchType), DispatchType.ToString())).GetDescription();
                return result;
            }
        }


    }

}
